<template>
  <div id="app">
    <keep-alive>
      <transition :name="transitionName"> 
        <router-view v-if="$route.meta.keepAlive">
            <!-- 这里是会被缓存的视图组件，比如列表A页面 -->
        </router-view>
      </transition>
    </keep-alive>

    <transition :name="transitionName"> 
      <router-view v-if="!$route.meta.keepAlive">
          <!-- 这里是不被缓存的视图组件，比如详情B页面-->
      </router-view>
    </transition>

  </div>
</template>

<script>
export default {
  name: 'App',
  data () {
    return {
      transitionName: ''
    }
  },
  watch: {//使用watch 监听$router的变化
    $route(to, from) {
      //如果to索引大于from索引,判断为前进状态,反之则为后退状态
      if(to.meta.index > from.meta.index){
        //设置动画名称
        this.transitionName = 'slide-left';
      }else{
        this.transitionName = 'slide-right';
      }
    }
  }
};
</script>

<style>
.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  will-change: transform;
  transition: all 600ms;
  position: absolute;
}
.slide-right-enter, .slide-right-leave-to {
  width: 100%;
  top: 0;
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}
.slide-right-leave-active {
  width: 100%;
  top: 0;
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
.slide-right-enter-active {
  top: 0;
  width: 100%;
}
.slide-left-enter, .slide-left-leave-to {
  width: 100%;
  top: 0;
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
.slide-left-leave-active {
  width: 100%;
  top: 0;
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}





* {
  box-sizing: border-box;
  line-height: 1;
}
*:before, *:after {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}
body, html {
  padding:0;
  margin:0;
}
a {
  text-decoration:none;
  outline:none;
  cursor: pointer;
}
input {
  border:1px solid #ccc;
  outline:none;
}
textarea {
  border:1px solid #ccc;
  outline:none;
}
h1,h2,h3,h4,h5,h6,p {
  font-weight:300;
  color:#333;
  line-height: 1.6;
  margin:0;
}
ul {
  margin: 0px;
  padding: 0px;
  list-style: none;
}
[v-cloak] {
  display: none;
}
.container {
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
  width: 96%;
  max-width: 1280px;
}
#app {
  font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.absoluteBackHome {
  position: fixed;
  top:10px;
  left: 10px;
  z-index: 9;
}

.markdownContainer h1, .markdownContainer h2, .markdownContainer h3, .markdownContainer h4, .markdownContainer h5, .markdownContainer p {
  line-height: 1.4;
  margin: 0 0 10px;
}
.markdownContainer code {
  padding: 2px 1em;
  line-height: 1.4;
  border: none;
  vertical-align: middle;
  white-space: pre-wrap;
  color: #c7254e;
  background-color: #f2f2f2;
}
.markdownContainer pre {
  padding: 1em;
  margin: 5px 0;
  line-height: 1.5;
  background: #2d2d2d;
  border-radius: 3px;
}
.markdownContainer pre code {
  background: none;
  color: #ccc;
  padding: 0;
}

</style>
